--应动非盲
local yindongfeimang = fk.CreateSkill {
    name = "mcdh_yindongfeimang",
}

local U = require "packages/utility/utility"
local lib = require "packages/mcdh/lib"

yindongfeimang:addEffect(fk.AfterCardsMove,{
    can_trigger = function(self, event, target, player, data)
        if not player:hasSkill(self) or player:usedSkillTimes(self.name, Player.HistoryTurn) > 0 then return false end
        for _, move in ipairs(data) do
            if move.from == player.id and move.to and move.to ~= move.from and move.toArea == Card.PlayerHand then
                for _, info in ipairs(move.moveInfo) do
                    if info.fromArea == Card.PlayerHand or info.fromArea == Card.PlayerEquip then
                        return true
                    end
                end
            end
        end
        return false
    end,
    on_cost = function(self, event, target, player, data)
        local room = player.room
        local source = nil
        for _, move in ipairs(data) do
            if move.from == player.id and move.to and move.to ~= move.from and move.toArea == Card.PlayerHand then
                for _, info in ipairs(move.moveInfo) do
                    if info.fromArea == Card.PlayerHand or info.fromArea == Card.PlayerEquip then
                        local current = move.to
                        if source == nil or current:getHandcardNum() > source:getHandcardNum() then
                            source = current
                        end
                        break
                    end
                end
            end
        end
        if source ~= nil then
            local targets =table.filter(player.room:getAlivePlayers(), function(p)
                        return p:getHandcardNum() < source:getHandcardNum()
                    end)
            if #targets > 0 then
                local players = room:askToChoosePlayers(
                        player,
                        {targets=targets,
                        min_num=1,
                        max_num=1,
                        prompt= "#mcdh_yindongfeimang-choice:" .. source.id,
                        skill_name=self.name})
        
                if #players > 0 then
                    event:setCostData(self,players[1])
                    return true
                end
            end
        end
        return false
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        event:getCostData(self):drawCards(2, self.name)
    end
})

Fk:loadTranslationTable{
    ["mcdh_yindongfeimang"] = "应动非盲",
    [":mcdh_yindongfeimang"] = "每回合限一次，其他角色获得你的牌后，你可以令一名手牌数小于其的角色摸两张牌。",
    ["#mcdh_yindongfeimang-choice"] = "应动非盲:令一名手牌数小于 %src 的角色摸两张牌。",
}
return yindongfeimang